<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item label="会议时间"> <el-date-picker v-model="meettimerange" type="daterange" value-format="yyyy-MM-dd" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" @change="meetTimeChange"> </el-date-picker> </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="queryParam.qry_state" clearable>
            <el-option v-for="item in codeModel.stateList" :key="item.code" :label="item.name" :value="item.code" clearable />
          </el-select>
        </el-form-item>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar ref="toolbar" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :isDisplayDeleteBatch="false" :isDisplayExport="false">
      <template slot="left-btn"> </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a
            >项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column prop="dispstate" label="状态" width="100px" sortable="custom" sort-by="state" align="center"></el-table-column>
        <el-table-column prop="docdate" label="单据日期" width="150px" sortable="custom" sort-by="docdate" align="center">
          <template slot-scope="scope">
            {{ scope.row.docdate | toDateTime('yyyy-MM-dd HH:mm') }}
          </template>
        </el-table-column>
        <el-table-column prop="usercode" label="申请人工号" width="100px" sortable="custom" sort-by="usercode" align="center"></el-table-column>
        <el-table-column prop="username" label="申请人姓名" width="100px" sortable="custom" sort-by="username" align="center"></el-table-column>
        <el-table-column prop="airlinecompany" label="会议室" min-width="200px" sortable="custom" sort-by="airlinecompany"></el-table-column>
        <el-table-column prop="begintime" label="会议时间" min-width="300px" sortable="custom" sort-by="begintime">
          <template slot-scope="scope"> {{ scope.row.begintime | toDateTime('yyyy-MM-dd HH:mm:ss') }} - {{ scope.row.endtime | toDateTime('yyyy-MM-dd HH:mm:ss') }} </template>
        </el-table-column>
        <el-table-column prop="name" label="会议主题" min-width="200px" sortable="custom" sort-by="name"></el-table-column>
        <el-table-column prop="docno" label="单据编号" width="140px" sortable="custom" sort-by="docno" align="center"></el-table-column>
        <el-table-column prop="latestphase" label="最新阶段" width="150px" sortable="custom" sort-by="latestphase" align="center"></el-table-column>
        <el-table-column label="操作" width="110px" v-slot="scope" fixed="right">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-edit" @click.native="openEditDialog('editForm', scope.row.id)">编辑</el-dropdown-item>
              <el-dropdown-item icon="el-icon-delete" :disabled="scope.row.state !== 0 && scope.row.state !== 2" @click.native="doDelete(scope.row.id)">删除</el-dropdown-item>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './edit'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'meetRoomApplyPage',
  mixins: [mixin_list],
  components: { tlEdit },
  data() {
    return {
      description: '会议室预订申请-列表查询',
      urlPrefix: '/meet/roomApply/',
      url: {
        queryCodeList: '/meet/roomApply/dataCodeList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'docdate',
        sord: 'desc'
      },
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              end.setTime(end.getTime() + 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              end.setTime(end.getTime() + 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              end.setTime(end.getTime() + 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      },
      meettimerange: "",
      queryParam: {
        qry_where: 'flowid > 0'
      }
    }
  },
  methods: {
    // 禁用表格前面的选择
    doDisableCheckBox(row, index) {
      if (row.state !== 0 && row.state !== 2) {
        return false
      } else {
        return true
      }
    },
    meetTimeChange(value) {
      if (value == null) {
        this.queryParam.qry_begintimebegin = ''
        this.queryParam.qry_begintimeend = ''
      } else {
        this.queryParam.qry_begintimebegin = value[0]
        this.queryParam.qry_begintimeend = value[1]
      }
    },
    beforeLoadData() {
      this.queryParam.qry_isquery = "1"
      return true
    },
    beforeDoDelete(ids) {
      // 判断是否能够删除
      ids += ''
      let idsArr = ids.split(',')
      for (let id of idsArr) {
        for (let apply of this.datas) {
          if (id === apply.id + '' && apply.state !== 0 && apply.state !== 2) {
            this.$tap.alert('审核状态下的申请记录不可删除！', 'warning')
            return false
          }
        }
      }
      return true
    }
  }
}
</script>

<style scoped></style>
